package lcr;

import java.util.HashSet;
import java.util.Set;

public class Test0067 {
}

class Solution0067_1 {
    public int findMaximumXOR(int[] nums) {
        int max = nums[0], mask = 0,ans=0;
        for (int num : nums) max = Math.max(max, num);
        int length=31-Integer.numberOfLeadingZeros(max);
        Set<Integer> set = new HashSet<>();
        for (int i = length; i >= 0; i--) {
            set.clear();
            mask|=1<<i;
            int newAns=ans|(1<<i);

            for (int num : nums) {
                int cur = num & mask;

                if (set.contains(newAns^cur)){
                    ans=newAns;
                    break;
                }
                set.add(cur);
            }
        }

        return ans;
    }
}